package com.ftwj.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ftwj.entity.SysRole;
import com.ftwj.service.SysRoleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/role")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;
    //根据角色名称获取对应的角色
    @GetMapping("/search")
    public List<SysRole> getRoleByRoleName(@RequestParam String roleName) {
        return sysRoleService.getRoleByRoleName(roleName);
    }
    //添加角色
    @PostMapping("/add")
    public boolean addRole(@RequestBody SysRole role) {

        return sysRoleService.addRole(role);
    }

    @PostMapping("/update")
    public boolean updateRole(@RequestBody SysRole role) {

        return sysRoleService.updateRole(role);
    }

    @DeleteMapping("/delete/{id}")
    public boolean deleteRole(@PathVariable String id) {

        return sysRoleService.deleteRole(id);
    }

    @PostMapping("/listRoles")
    public ResponseEntity<PageInfo<SysRole>> getAllRoles(@RequestBody SysRole sysRole) {
        Integer pageNumber = sysRole.getPageNumber();
        Integer pageSize = sysRole.getPageSize();
        // 调用Service方法获取数据
        PageInfo<SysRole> page = sysRoleService.getAllRoles(pageNumber, pageSize);
        return ResponseEntity.ok(page);
    }

}
